package com.zhong.thesimpleconnection.service;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;

import com.zhong.thesimpleconnection.R;
import com.zhong.thesimpleconnection.util.MyFileObserver;

import java.io.File;

/**
 * Created by 俊峰 on 2017/5/18.
 * 用于监听MyCryptSecret文件夹的状态
 */

public class ServiceToMonitorFile extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        File file = new File(Environment.getExternalStorageDirectory(), "MyCryptSecret");
        if (file.exists()) {
//            MyFileObserver observer = new MyFileObserver(file.getPath(), getApplicationContext());
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
            Notification notification = builder.setSmallIcon(R.mipmap.rpt)
                    .setContentTitle(this.getResources().getString(R.string.Dialog_Warn_Warn_Title))
                    .setContentText(this.getResources().getString(R.string.Notification_About_File))
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(this.getResources().getString(R.string.Notification_About_File_Big_First)))
                    .build();
            NotificationManager managerCompat = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
            managerCompat.notify(0, notification);
//            observer.startWatching();
        }
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
